package com.pattern.decorator;


/**
 * @author Mr.yuan
 * @version v1.0
 * @date 2019/7/26 13:53
 **/
public class DecoratorPattern {
    public static void main(String[] args) {
        Circle circle = new Circle();
        Shape redCircle = new RedShapeDecorator(new Circle());
        Shape redRectangle = new RedShapeDecorator(new Rectangle());
        System.out.println("normal shape border");
        circle.draw();
        System.out.println("circle shape border");
        redCircle.draw();
        System.out.println("rectangle shape border");
        redRectangle.draw();
    }

    private static class Circle implements Shape {
        @Override
        public void draw() {
            System.out.println("shape: circle");
        }
    }
    private static class Rectangle implements Shape {
        @Override
        public void draw() {
            System.out.println("shape: rectangle");
        }
    }

    private interface Shape {
        void draw();
    }

    private static abstract class ShapeDecorator implements Shape{
        protected Shape shape;

        ShapeDecorator(Shape shape) {
            this.shape = shape;
        }

        @Override
        public void draw() {
            shape.draw();
        }
    }
    private static class RedShapeDecorator extends ShapeDecorator {

        RedShapeDecorator(Shape shape) {
            super(shape);
        }

        @Override
        public void draw() {
            shape.draw();
            setBorder(shape);
        }

        public void setBorder(Shape border) {
            System.out.println("border color : red");
        }
    }
}
